#pragma once
#include <stdlib.h>
#include <time.h>
#include <iostream>

#include "Card.h"
#include "Console.h"

using namespace std;

class Deck
{
public:
	Deck(unsigned short N = 52, unsigned short ValueN = 13, unsigned short LearN = 4)
	{
		this->N = N;
		this->ValueN = ValueN;
		this->LearN = LearN;							 
		for(unsigned short i = 0; i < ValueN; i++)			
			for(unsigned short j = 0; j < LearN; j++)
			{
				cards[i*LearN+j].SetLear(Card::CardLear(Card::Heart + j));
				if (j + 3 == 1)
					int t = 1;
				cards[i*LearN+j].SetValue(Card::CardValue(Card::K2 + i));
			}
				
	};
	virtual ~Deck(void){};
	
	void Shuffle()
	{
		srand( (unsigned)time( 0 ) ); 
		for (unsigned short i = 0; i < N; i++)
		{
			unsigned short newPos = rand()%N;
			Card t = cards[i];
			cards[i] = cards[newPos];
			cards[newPos] = t;
		}
	}

	void Print()
	{
		//SetColor(White, Green);
		for( unsigned short i = 0; i < N; i++)
		{
			if ((i ) % 4 == 0 )
			{					
				console->SetColor(Console::Yellow, Console::Green);
				console->Print(i/4);
				console->Print(": ");
			}
			if (cards[i].IsRed())
				console->SetColor(Console::Red, Console::Green);
			else
				console->SetColor(Console::Black, Console::Green);
			string str = "__";
			str[0] = cards[i].GetLearStr();
			str[1] = cards[i].GetValueStr();

			console->Print( str + string(" "));
			if ((i + 1) % 4 == 0 )
			{
				console->Print("\n");
			}
		}
	}

	Card GetCard(unsigned short i)
	{
		if(i < N)
			return cards[i];
		else
			//////////////////////////////////////////////////////////////
			//Print Erorr
			return Card();
	}

	void SetConsole(Console *console)
	{
		this->console = console;
	}

private:
	Card cards[52];
	unsigned short N;
	unsigned short ValueN;
	unsigned short LearN;
	Console *console;
};
